/*
 * TAuthenticator.h
 *
 *  Created on: 2012-10-30
 *      Author: minhua
 */

#ifndef TAUTHENTICATOR_H_
#define TAUTHENTICATOR_H_

#include <QNetworkReply>
#include "../model/TSession.h"
#include <QTime>

class QSslError;

class TAuthenticator : public QObject
{
	Q_OBJECT

// Member
private:
	QString _loginName;
	QString _password;
	QString _oldPassword;

// Method
public:
	TAuthenticator(QObject *parent = 0);
	TAuthenticator(QString loginName, QString password, QObject *parent = 0);
	TAuthenticator(QString loginName, QString oldPassword, QString newPassword, QObject *parent = 0);
	virtual ~TAuthenticator();
	void login();
	void modifyPassword();

private:
	void innerLogin(QNetworkAccessManager *manager);

// Signal
signals:
	void loginFinished(bool error, TSessionPointer session);
	void modifyPasswordFinished(bool error);

// Slot
private slots:
	void done(QNetworkReply *reply);
	void modifyDone(QNetworkReply *reply);
	void sslErrors(QNetworkReply*,const QList<QSslError> &errors);

private:
	QTime _timeCounter;
};

#endif /* TAUTHENTICATOR_H_ */
